home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000174_icon-group-sender_Mon Dec 18 09:27:24 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id eBIGRKk01190
  4.     for icon-group-addresses; Mon, 18 Dec 2000 09:27:20 -0700 (MST)
  5. Message-Id: <200012181627.eBIGRKk01190@baskerville.CS.Arizona.EDU>
  6. Date: Sat, 16 Dec 2000 08:26:58 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: icon-group@cs.arizona.edu
  10. Subject: Re: Stepping
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 3005
  14.  
  15. John Sampson wrote:
  16. > It would be useful to be able to step through an Icon program or set
  17. > break-points in some simple way. I would have thought
  18. > dummy := read()
  19. > ...
  20.  
  21. I though others might like to see how this idea can be easily extended
  22. to support a simple debugging controller.  The following procedure
  23. pauses the program and allows the user to type some simple debugging
  24. commands.  Typing EOF or "q" terminates the program, "c" or "n" continues
  25. program execution, "l" shows local (and global) variables, "g" shows
  26. only global variables, and "a" shows a stack trace of all variables.
  27. Finally "h" prints a simple help message.
  28.  
  29. The programmer can pass in a special prompt or let it default to
  30. a standard prompt.  (Passing in a prompt makes it easier to
  31. identify where in the program you've paused...).
  32.  
  33. Of course, you could extend this to add any number of commands, and
  34. even write a version where the programmer could optionally pass in
  35. addition commands to allow when the procedure is called.
  36.  
  37. I think I've seen better versions of similar ideas posted before - a
  38. *long* time ago.  If you have one, how about reposting it?
  39.  
  40. (As an aside, this could become a class in Unicon and do some *really*
  41. impressive debugging...)
  42.  
  43. ---- snip "debug.icn" ---
  44. #
  45. # Simple debugger controller.  Responds to user-issued debug commands.
  46. #
  47. #   Still requires user to press Enter after each command, though EOF
  48. #     terminates program immediately.
  49. #
  50. procedure debugCtl(prompt)
  51.  
  52.     # Loop until user quits program or asks to continue
  53.     #
  54.     repeat {
  55.         writes((\prompt | "Debug")," (h for help): ")
  56.  
  57.         (map(read()) | "q") ? {
  58.  
  59.             if ="q" then stop("Program terminated by user.")
  60.  
  61.             else if ="h" then {  # help message
  62.                 write("\nCommands are:\n")
  63.                 write("\tquit (or EOF) -- terminate program now")
  64.                 write("\thelp          -- display help")
  65.                 write("\tcontinue      -- continue program execution")
  66.                 write("\tnext          -- same as continue")
  67.                 write("\tlocals        -- display local variables")
  68.                 write("\tglobals       -- display global variables")
  69.                 write("\tall           -- display all variables in stack trace")
  70.                 write("\nOnly first character of command is needed.\n")
  71.                 }
  72.  
  73.             else if =("c"|"n") then return      # continue execution
  74.     
  75.             else if ="l" then {  # display local (and global) variables
  76.                 display(2)       # to bad it also shows local vars for debugCtl!
  77.                 }
  78.  
  79.             else if ="g" then {  # display only global variables
  80.                 display(0)
  81.                 }
  82.  
  83.             else if ="a" then {  # display full stack dump
  84.                 display()
  85.                 }
  86.  
  87.             }   # end of string scanning
  88.  
  89.         }   # end of repeat loop
  90.  
  91. end
  92. --- end snip "debug.icn" ----
  93.  
  94. --
  95. Steve Wampler-  SOLIS Project, National Solar Observatory
  96. swampler@noao.edu
  97.